package 家庭作业;

/*
 * 4)现在有如下一个数组： 
	int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}; 
	要求将以上数组中的0项去掉，将不为0的值存入一个新的数组，生成新的数组为 
	int newArr[]={1,3,4,5,6,6,5,4,7,6,7,5};*/
import java.util.Arrays;

public class Test {

	public static void main(String[] args) {
		int oldArr[] = { 1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5 };
		int[] newArr = {};
		for (int i = 0; i < oldArr.length; i++) {
			if (oldArr[i] != 0) {
				int[] b = Arrays.copyOf(newArr, newArr.length + 1);
				b[b.length - 1] = oldArr[i];
				newArr = b;
			}
		}
		System.out.println(Arrays.toString(newArr));
	}

}
